package lab02.test23;

import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * 从命令行输入你的生日信息，
 * 然后计算你的生日还有多少天，
 * 你的生日是星期几。
 */
public class Text {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入你出生的年月日，格式形如：20000520:");

        Calendar calendar = Calendar.getInstance();

        String str = scanner.nextLine();

        String year = str.substring(0,4);

        String month = str.substring(4,6);

        String day = str.substring(6);

        calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer. parseInt(day));

        System.out.println("输出对应的是星期几:");

        int week = calendar.get(Calendar.DAY_OF_WEEK);

        switch (week) {
            case 1:
                System.out.println("周一");
                break;

            case 2:
                System.out.println("周二");
                break;

            case 3:
                System.out.println("周三");
                break;

            case 4:
                System.out.println("周四");
                break;

            case 5:
                System.out.println("周五");
                break;

            case 6:
                System.out.println("周六");
                break;

            default:
                System.out.println("周日");
                break;
        }

        Date date2 = new Date();

        calendar.set(2017,Integer.parseInt(month),Integer.parseInt(day));

        Date date1 = calendar.getTime();

        long countDay = (date1.getTime()-date2.getTime())/(24*60*60*1000);

        if(countDay < 0){

            calendar.set(2018,Integer.parseInt(month),Integer.parseInt(day));

            date1 = calendar.getTime();

            countDay = (date1.getTime() - date2.getTime())/(24*60*60*1000);

        }

        System.out.println("距离你的生日还有"+countDay+"天。");
    }

}

